package com.example.mq.api;

import com.example.mq.annoation.AuthorizationName;
import com.example.mq.config.mq.MqProducerService;
import com.example.mq.controller.base.BaseController;
import com.example.mq.model.Menu;
import com.example.mq.model.QMenu;
import com.example.mq.repository.MenuRepository;
import com.querydsl.core.types.Predicate;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.repository.query.JpaQueryCreator;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 邹宇杰
 * @email 2901570623@qq.com
 * @site http://zouyujie.top
 * @date 2022/3/14 23:00
 */
@RestController
public class ApiController extends BaseController {

    @Autowired
    MqProducerService mqProducerService;

    private static final Logger logger = LoggerFactory.getLogger(ApiController.class);

//    @GetMapping("/")
//    public Object get(){
//        SendResult sendResult = null;
//        try {
//            Message msg1 = new Message("topic1", "tag1", "hello1".getBytes(RemotingHelper.DEFAULT_CHARSET));
//            Message msg2 = new Message("topic1", "tag2", "hello2".getBytes(RemotingHelper.DEFAULT_CHARSET));
//            Message msg3 = new Message("topic1", "tag3", "hello3".getBytes(RemotingHelper.DEFAULT_CHARSET));
//            Message msg4 = new Message("topic1", "tag4", "hello4".getBytes(RemotingHelper.DEFAULT_CHARSET));
//            List<Message> messageList = List.of(msg1, msg2, msg3, msg4);
//            mqProducerService.batchSendAsync(messageList);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return sendResult;
//    }

    @GetMapping("/hello")
    @PreAuthorize("hasAuthority('mmm')")
    public String hello() {

        logger.info("hello");
        return "hello";
    }
}
